<?php

namespace App\Http\Controllers\Admin;

use App\Http\Config\ErrorCode;
use App\Models\Admin\Configs;
use Illuminate\Http\Request;

class SiteconfigController extends BaseController
{
    public function __construct(Request $request)
    {
        parent::__construct($request);
    }

    //配置列表
    public function getDataList()
    {
        $configModel = new Configs();
        $data = $configModel->getConfigByID();
        $this->returnData["data"] = $data;
        return response()->json($this->returnData);
    }

    //更新系统配置
    public function update(Request $request){
        $id = $request->post('id');
        if($request->post('type') == "basic"){
            $data['title'] = $request->post('title');
            $request->post('version') ? $data['version'] = $request->post('version') : "";
            $request->post('sms_appid') ? $data['sms_appid'] = $request->post('sms_appid') : "";
            $request->post('sms_appkey') ? $data['sms_appkey'] = $request->post('sms_appkey') : "";
            $data['qy_redirect'] = $request->post('qy_redirect'); //
            $data['agent_url'] = $request->post('agent_url');
            $data['seo_title'] = $request->post('seo_title');
        }else if($request->post('type') == "qy"){
            $data['company_id'] = $request->post('company_id');
            $data['tongxl_secret'] = $request->post('tongxl_secret');
            $data['push_secret'] = $request->post('push_secret');
            $data['qy_mch_id'] = $request->post('qy_mch_id');
            $data['qy_pay_secret'] = $request->post('qy_pay_secret');
            $data['qy_appid'] = $request->post('qy_appid');
        }else if($request->post('type') == "weixin"){
            $data['wechat_appid'] = $request->post('wechat_appid');
            $data['wechat_secret'] = $request->post('wechat_secret');
            $data['member_wechat_appid'] = $request->post('member_wechat_appid');
            $data['member_wechat_secret'] = $request->post('member_wechat_secret');
            $data['member_wechat_version'] = $request->post('member_wechat_version');
        }else{
            $this->returnData = ErrorCode::$admin_enum['not_exist'];
            $this->returnData['msg'] = 'type参数错误';
            return response()->json($this->returnData);
        }
        $configModel = new Configs();
        $res = $configModel->configUpdate($id,$data);
        if(!$res){
            $this->returnData = ErrorCode::$admin_enum['not_exist'];
            $this->returnData['msg'] = '更新失败';
            return response()->json($this->returnData);
        }
        $this->returnData['msg'] = "更新成功";
        return response()->json($this->returnData);
    }

}
